import Vue from 'vue'
import VueRouter from 'vue-router'
import NProgress from 'nprogress'
import '../../node_modules/nprogress/nprogress.css'

Vue.use(VueRouter);

import Login from "@/components/Login.vue";
import Order from "@/components/Order.vue";
import Register from "@/components/Register.vue";
import Shuiguo from "@/components/Shuiguo.vue";
import Shucai from "@/components/Shucai.vue";
import Time from "@/components/Time.vue";
import User from "@/components/User.vue";


let router = new VueRouter({
    //路由匹配
    routes: [
        {
            path: "/",
            component: Login
        },
        { path: "/Login", component: () => import(/* webpackChunkName: "mylogin" */ "@/components/Login") },
        { path: "/Order", component: Order },
        { path: "/Register", component: Register },
        { path: "/Shucai", component: Shucai },
        { path: "/Shuiguo", component: Shuiguo },
        { path: "/Time", component: Time },
        {
            path: "/User", component: User,
            //嵌套子路由的内容显示在父组件的router-view里面
            children: [{
                path: "Time",
                component: Time
            },
            {
                path: "Order",
                component: Order
            },
            {
                path: "",
                component: Order
            },
            ]
        },
    ]
})

// 前导航守卫
router.beforeEach((to, from, next) => {
    NProgress.set(0.3);
    next();
})
// 后导航守卫
router.afterEach((to, from) => {
    NProgress.done();
})

export default router;